<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.scalar.chiptrack.operations.material.forms.MaterialRequestForm"%>
<%@ page import="com.scalar.chiptrack.operations.material.MaterialRequestLineItem" %>
<%@ page import="com.scalar.chiptrack.utils.ConfigManager"%>
<%@ page import="com.scalar.chiptrack.users.Functionality" %>
<%@ page import="com.scalar.chiptrack.users.User" %>
<%@ page import="com.scalar.chiptrack.commons.SessionKeys" %>
<%@ page import="com.scalar.chiptrack.commons.Constants" %>
<%@ page import="com.scalar.chiptrack.utils.StringUtils" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/materialRequest.do"/>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<% User user1 = (User)session.getAttribute (SessionKeys.USER_KEY); %>
<html:html locale="true">
<HEAD>
<TITLE>Scalar Soft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>
<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>

<BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<%
     String action = ((request.getParameter("action")!=null)?(request.getParameter("action")):"view").trim();
    // code the get the Material Request Line Items Linked List
      java.util.LinkedList lineItemlist = null;
      try{
         lineItemlist = (java.util.LinkedList)request.getAttribute("lineItemList");
         if(lineItemlist==null) lineItemlist = new java.util.LinkedList();
       }catch(Exception ex){
     }

     // code to get the materialRequest Id which used to tramsfer this number to print action
     int materialrequestId = -1;
     try{
         materialrequestId = Integer.parseInt(request.getParameter("materialrequestId"));
     }catch(Exception ex){  }

    MaterialRequestForm materialRequestForm1 = null;    
    String materialRequestNumber = "";
    if ("confirmdelete".equalsIgnoreCase(action) == true) {
      try{  
        materialRequestForm1 = (MaterialRequestForm)request.getAttribute("materialRequestForm");
        materialRequestNumber = materialRequestForm1.getMaterialRequestNumber();
       }catch(Exception e){  }
    }  
   
    %>
<script language="javascript">
// script for open new window showing printable version.
function printableMaterialRequest(materialrequestId) {
    var materialRequestViewURL = '<%=chipTracContext%>/materialRequest.do?action=printView&materialrequestId=' + materialrequestId
    newWindow = window.open (materialRequestViewURL,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,resizable=yes');
    newWindow.focus();
}
// script to delete Material Request
<% if ("confirmdelete".equalsIgnoreCase(action) == true) { %>
    function deleteMaterialRequest(materialrequestId) {

       var materialRequestDeleteURL = '<%=chipTracContext%>/materialRequest.do?action=delete&materialrequestId=' + materialrequestId + '&materialRequestNumber=<%=materialRequestNumber%>';
       document.materialRequestForm.action = materialRequestDeleteURL;
       document.materialRequestForm.submit();
    }
<% } %>
</script>

<%@include file="/jsp/includes/header.jsp" %>

<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<!-- Side Navigation start -->
<%@include file="/jsp/operations/operations_menu.jsp" %></TD>
<!-- end of the side navigations -->

<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD valign="top" width="100%"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR><BR><!--<BR><BR><BR><BR>-->
<center><span class="NArialW">Materials Transfer Request and Authorization </span></center>
<!-- from here your body starts -->

<table border="0" width="95%" align=right cellspacing='3'>
     <tr>
        <% if("confirmdelete".equalsIgnoreCase(action) == true){
            
        %>
        <td colspan=4 width="100%" align="left" >
         <font class="NArialS"><img src='<%=chipTracContext%>/jsp/includes/images/spacer.gif' border='0' height='10' width='1'>
         <!--Bhaskar added this scriptlet on 16 july 2003 enable a blue message to be displayed.-->
         <!--% if ( !user1.isActionAllowed ( Functionality.MATERIAL_REQUEST, 
         User.USER_ACTION_DELETE ) ) { %>
            <font class='NArialS'><font color='blue'><b>< %=Constants.NO_MODIFY_RIGHTS %></font></b><BR>
        < % } %-->    
        <font color="red"> <b>Are you sure, you want to delete this Materials Request ?</b> &nbsp;&nbsp; </font>
        <chiptrack:restrictedLink functionality='<%=Functionality.MATERIAL_REQUEST%>' action='<%=User.USER_ACTION_DELETE%>' href='<%="javascript:deleteMaterialRequest(" + materialrequestId+")" %>' onmouseover="window.status='Click for Confirm to Delete Materials Request';return true" onmouseout="window.status='';return true">
        <img border="0" src="<%=chipTracContext%>/jsp/includes/images/confirm.gif" title="Click here for Confirm to Delete Materials Request" > </chiptrack:restrictedLink>
        &nbsp;&nbsp;</font>
        <chiptrack:restrictedLink functionality='<%=Functionality.MATERIAL_REQUEST%>'  href="/chiptrack/materialRequest.do" onmouseover="window.status='Click to Cancel and go Back';return true" onmouseout="window.status='';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" title="Click here to Cancel and go Back"> </chiptrack:restrictedLink>
        <br><br>
        </td>
        <% } %>
        <% if("view".equalsIgnoreCase(action) == true){ %>
        <td colspan=4 width="100%" align="center" >
        <font class="NArialS"><img src='<%=chipTracContext%>/jsp/includes/images/spacer.gif' border='0' height='10' width='1'>
        <chiptrack:restrictedLink functionality='<%=Functionality.MATERIAL_REQUEST%>' action='<%=User.USER_ACTION_VIEW%>' href='<%="javascript:printableMaterialRequest(" + materialrequestId+")" %>' onmouseover="window.status='Click for Materials Request Print View ';return true" onmouseout="window.status='';return true" >
        [Printer-Friendly Version] </chiptrack:restrictedLink>
        &nbsp;&nbsp;</font>
        <br><br>
        </td>
        <% } %>
        
    </tr>
<html:form name="materialRequestForm" action="/materialRequest" method="post" type="com.scalar.chiptrack.operations.material.forms.MaterialRequestForm">
     <html:hidden name="materialRequestForm" property="materialRequestId"  />
    <tr>
       <td width="21%"><font class="NArialL">Materials Request Number :</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="materialRequestNumber" styleClass="txfield" size="23" maxlength="50" disabled="true" /></td>
       
       <td width="21%"><font class="NArialL">Cost Center :</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="costCenter" size="23" styleClass="txfield" disabled="true"/></td>
      
    </tr>

    <tr>
       <td width="21%"><font class="NArialL">Issuing Department (Int):</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="internalIssueDepartment" styleClass="txfield" size="23" maxlength="50" disabled="true"/></td>
       
       <td width="21%"><font class="NArialL">Receiving Department (Int):</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="internalReceivingDepartment" styleClass="txfield" size="23" maxlength="50" disabled="true"/></td>
     
    </tr>
    <tr>
       <td width="21%"><font class="NArialL">Issuing Department (Ext):</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="externalIssueDepartment" styleClass="txfield" size="23" maxlength="50" disabled="true"/></td>
       
       <td width="21%"><font class="NArialL">Receiving Department (Ext):</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="externalReceivingDepartment" styleClass="txfield" size="23" maxlength="50"  disabled="true" /></td>
       
    </tr>
         <tr>
       <td width="21%"><font class="NArialL">Requested By:</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="requestedBy" size="23" styleClass="txfield" disabled="true"/></td>
       
       <td width="21%"><font class="NArialL">Date Needed By :</font></td>
        <td width="21%"><font class="NArialL">
         <html:text name="materialRequestForm" property="dateNeededBy" size="23" styleClass="txfield" disabled="true"/>
          </td>
       </tr>
     <tr>
      <td width="21%"><font class="NArialL">Authorized by:</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="authorizedBy" size="23" styleClass="txfield" disabled="true" /></td>
       
      <td width="21%"><font class="NArialL">Authorized Date :</font></td>
      <td width="21%"><html:text name="materialRequestForm" property="authorizedDate" size="23" styleClass="txfield" disabled="true"/></td> 
      
       </tr>
       <tr>
       <td width="21%"><font class="NArialL">Request Authorized By:</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="requestAuthorizedBy" size="23" styleClass="txfield" disabled="true" /></td>
         
       <td width="21%"><font class="NArialL">Request Authorized Date:</font></td>
       <td width="21%"><html:text name="materialRequestForm" property="requestAuthorizedByDate" size="23" styleClass="txfield" disabled="true" /></td>
       
       </td></tr>
       <tr>
        <td width="21%"><font class="NArialL">Description:</font></td></tr>
        <tr>
       <td colspan='4'><html:textarea rows="5" cols="80" name="materialRequestForm" property="description"  styleClass="txfield" disabled="true" /></td>
    
     </tr>
     <tr><td width="3%">&nbsp;</td></tr>

      <tr><td colspan='4'>
      <table width='80%' align='left' border='0'>
         <tr>
            <td width="10%" align="center" bgcolor="#993333"><font class="NArialL">
               <font color="#FFFFFF">Line No:</font></td>
            <td width="30%" align="center" bgcolor="#993333"><font class="NArialL">
               <font color="#FFFFFF">Qty Requested:</font></td>
            <td width="30%" align="center" bgcolor="#993333"><font class="NArialL">
               <font color="#FFFFFF">Qty Received:</font></td>
            <td width='30%' align="center" bgcolor="#993333"><font class="NArialL">
                <font color="#FFFFFF"><bean:message key = "label.mfgPartNumber" /></font></td>
          </tr>
            <% 
               int count = 0;
               java.util.ListIterator lineItemIterator = lineItemlist.listIterator(0);
               MaterialRequestLineItem materialRequestLineItem = null;
               while(lineItemIterator.hasNext()){ 
                   materialRequestLineItem = (MaterialRequestLineItem)lineItemIterator.next();
                   if(materialRequestLineItem==null)continue;
             %>
            <tr>
                <td width="10%" align="center" bgcolor="#DEE1E2">
                <input type="text" name="lineItemNo" size="6" value="<%=(count+1)%>" disabled="disabled" class="txfield"></td>
                <td width="30%" align="center" bgcolor="#DEE1E2"><font class="NArialL"><font color="#000000">
                <input type="text" name="reqQuantity_<%=count%>" value="<%=StringUtils.formatUnits(materialRequestLineItem.getRequestQuantity())%>"  size='20' maxlength='9' class="valuetxfield" disabled="disabled">
                </font></td>
                <td width="30%" align="center" bgcolor="#DEE1E2"><font class="NArialL"><font color="#000000">
                <input type="text" name="recQuantity_<%=count%>" value="<%=StringUtils.formatUnits(materialRequestLineItem.getReceivedQuantity())%>"  size='20' maxlength='9' class="valuetxfield" disabled="disabled">
                </font></td>
                <td width="30%" align="center" bgcolor="#DEE1E2"><font class="NArialL"><font color="#000000">
                <html:select  property="partNumber" styleClass="txfield" value="<%=materialRequestLineItem.getPartNumber()%>"  disabled="true">      	   
                <html:option value="-1">-- Select one --</html:option>
                <html:options collection="partNumberList" property="value" labelProperty="label"/>
                </html:select>
                </font></td>
           </tr>
           <%
            count++;
             } 
             if(count == 0){
             %>
             <tr>
                <td colspan="4" align="center" bgcolor="#DEE1E2">
                       <font class="NArialL">No Material Request LineItems</font>
                </td>
           </tr>

             <%
            }
           %>   
            
      </table>
      </td></tr>
        <tr>
        <td colspan=5>&nbsp;
        </td>
        </tr>
        <tr>
       <td colspan=5 align=center>
        <chiptrack:restrictedLink functionality='<%=Functionality.MATERIAL_REQUEST%>'  href="/chiptrack/materialRequest.do" onmouseover="window.status='Click for Back to Material Search';return true" onmouseout="window.status='';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/back.gif" title="Click for Back to Material Search"> </chiptrack:restrictedLink>
         <!--a href="javascript:history.back();" onMouseOver="window.status='Back to Material Request Main Page';return true" onMouseOut="window.status='';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/back.gif" ></a-->
      </td>
      </tr>
     </table>
</html:form>

<!--<BR><BR><BR>--></TD></TR>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

<!-- Footer starts here -->

<%@include file="/jsp/includes/footer.jsp" %>

<!-- footer end here -->
</BODY>
</html:html>